﻿using System;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_NpcChatPacket : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_NpcChatPacket ).FullName );

        private byte[] _byte = null;

        public S_NpcChatPacket( L1NpcInstance npc, String chat, int type )
        {
            buildPacket( npc, chat, type );
        }

        private void buildPacket( L1NpcInstance npc, String chat, int type )
        {
            switch ( type )
            {
                case 0: // normal chat
                    writeC( Opcodes.S_OPCODE_NPCSHOUT ); // Key is 16 , can use
                    // desc-?.tbl
                    writeC( type ); // Color
                    writeD( npc.getId() );
                    writeS( npc.getName() + ": " + chat );
                    break;

                case 2: // shout
                    writeC( Opcodes.S_OPCODE_NPCSHOUT ); // Key is 16 , can use
                    // desc-?.tbl
                    writeC( type ); // Color
                    writeD( npc.getId() );
                    writeS( "<" + npc.getName() + "> " + chat );
                    break;

                case 3: // world chat
                    writeC( Opcodes.S_OPCODE_NPCSHOUT );
                    writeC( type ); // XXX 白色になる
                    writeD( npc.getId() );
                    writeS( "[" + npc.getName() + "] " + chat );
                    break;

                default:
                    break;
            }
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_NpcChatPacket";
        }
    }
}
